package com.thirteen.app.utils;

import com.thirteen.app.Interceptors.JWTAdminInterceptor;
import com.thirteen.app.Interceptors.JWTStudentInterceptor;
import com.thirteen.app.Interceptors.JWTTeacherInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> excludePath = new ArrayList<>();
        excludePath.add("/api/login");     //用户登录
        excludePath.add("/api/admin/login");     //管理员登录
        excludePath.add("/static/**");  //静态资源
        excludePath.add("/assets/**");  //静态资源
        registry.addInterceptor(new JWTStudentInterceptor())
                .addPathPatterns("/api/student/**")
                .excludePathPatterns(excludePath);
        registry.addInterceptor(new JWTTeacherInterceptor())
                .addPathPatterns("/api/teacher/**")
                .excludePathPatterns(excludePath);
        registry.addInterceptor(new JWTAdminInterceptor())
                .addPathPatterns("/api/admin/**")
                .excludePathPatterns(excludePath);

    }
}
